home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / ada / c01oop.zip / CPPWKBK / CPPV3-3.CPP < prev    next >
C/C++ Source or Header  |  1992-08-25  |  1KB  |  59 lines

  1. #define HEADER "C++ Problem 3.3 by Rick Conn using Borland C++"
  2.  
  3. #include <stdio.h>
  4. #include <string.h>  // for strcpy()
  5. #include <mem.h>     // for memcpy()
  6.  
  7. class note {
  8.   char text[40];
  9. public:
  10.   note (char *cp = "");
  11.   void print (void);
  12. };
  13.  
  14. class note_book {
  15.   note *narray[10];
  16.   int number_of_notes;
  17. public:
  18.   note_book();
  19.   void add (note *);
  20.   void print(void);
  21. };
  22.  
  23. note::note (char *value) { strcpy(text, value); }
  24.  
  25. void note::print(void) { printf("Note: %s\n", text); }
  26.  
  27. note_book::note_book() { number_of_notes = 0; }
  28.  
  29. void note_book::add (note *newnote) {
  30.   narray[number_of_notes] = newnote;
  31.   number_of_notes++;
  32. }
  33.  
  34. void note_book::print(void) {
  35.   int i;
  36.  
  37.   for (i=0; i<number_of_notes; i++) {
  38.     printf("%2d: ", i);
  39.     narray[i] -> print();
  40.   }
  41. }
  42.  
  43. void main(void)
  44. {
  45.   printf("%s\n", HEADER);
  46.  
  47.   note_book nb;
  48.  
  49.   note n1("This is a test");     note n2("This is only a test");
  50.   note n3("How far will I go?"); note n4("Perhaps just so far");
  51.   note n5("This is fun");        note n6("This is boring");
  52.   note n7("This works");
  53.  
  54.   nb.add (&n1);  nb.add (&n2);  nb.add (&n3);  nb.add (&n4);
  55.   nb.add (&n5);  nb.add (&n6);  nb.add (&n7);
  56.  
  57.   nb.print();
  58. }
  59.